import {BaseModel} from "../BaseModel";

export class Chapter extends BaseModel{

    constructor(){
        super();
        this.symbolName = "Chapter";
        this.tableName = "t_chapter";
        this.id = '';//主键id
        this.name = '';//名称
        this.thumb = '';//缩略图
        this.brief = '';//简介
        this.bookId = '';//关联的书本id
        this.sortIndex = -1;//排序
        this.reverse1 = '';//备用字段1
        this.reverse2 = '';//备用字段2
        this.reverse3 = '';//备用字段3
    }

    dbMapper(){
        return {
            id: 'id',
            name: 'name',
            thumb: 'thumb',
            brief: 'brief',
            bookId: 'book_id',
            sortIndex: 'sort_index',
            reverse1: 'reverse1',
            reverse2: 'reverse2',
            reverse3: 'reverse3'
        }
    }

    /**
     * 输出转换
     * @param obj
     * @returns {Book}
     */
    mappingModel(obj){
        let chapter = new Chapter();
        chapter.id = obj.id ? obj.id : ''
        chapter.name = obj.name ? obj.name : ''
        chapter.thumb = obj.thumb ? obj.thumb : ''
        chapter.brief = obj.brief ? obj.brief : ''
        chapter.bookId = obj.book_id ? obj.book_id : ''
        chapter.sortIndex = obj.sort_index ? obj.sort_index : -1
        chapter.reverse1 = obj.reverse1 ? obj.reverse1 : ''
        chapter.reverse2 = obj.reverse2 ? obj.reverse2 : ''
        chapter.reverse3 = obj.reverse3 ? obj.reverse3 : ''
        return chapter;
    }

}
